import React, {PropsWithChildren} from 'react'
import {SubGoodsResponse} from "../apis/GoodsApi";
import {Table, TableProps} from "antd";
import {buildSortCompareFunction, useTableSearchTextColumnProps} from "../utils/AntdTableUtils";

export interface SubGoodsTableProps extends PropsWithChildren {
    data: SubGoodsResponse[]
}

const SubGoodsTable: React.FC<SubGoodsTableProps> = ({data}) => {
    let searchNameTableColumnProps = useTableSearchTextColumnProps<SubGoodsResponse>("name", {
        placeholder: "名字"
    });

    let numberSearchColumnProps = useTableSearchTextColumnProps<SubGoodsResponse>("number", {
        placeholder: "编号"
    });
    const columns: TableProps<SubGoodsResponse>['columns'] = [
        {
            key: "number",
            dataIndex: 'number',
            title: "编号",
            ...numberSearchColumnProps,
            onFilter: (value, record) => {
                return record.number.toLowerCase().includes((value as string).toLowerCase())
            } ,
            sorter:buildSortCompareFunction("number")
        },
        {
            key: "name",
            dataIndex: "name",
            title: "名称",
            ...searchNameTableColumnProps,
            onFilter: (value, record) => {
                return record.name.toLowerCase().includes((value as string).toLowerCase())
            } ,
            sorter:buildSortCompareFunction("name"),
        }, {
            key: "amount",
            dataIndex: "amount",
            title: "库存",
        }, /*{
            key: "action",
            title: "操作",
            render: () => {
                return <Space>
                    {employeeAuthorizationStore.hasAuthority("货品_修改") &&
                        <Button type={"link"}
                                onClick={(event) => {
                                    event.stopPropagation()
                                    setEditingGoodsId(item.id)
                                }}>
                            <EditOutlined/>
                        </Button>}
                    {employeeAuthorizationStore.hasAuthority("货品_删除") &&
                        <LoadableButton
                            type={"link"}
                            danger
                            onClick={async (event) => {
                                event.stopPropagation()
                                await deleteGoods(item.id);
                                await query()
                            }}>
                            <DeleteOutlined/>
                        </LoadableButton>}
                </Space>
            }
        }*/
    ]
    return <>
        <Table columns={columns} dataSource={data}/>
    </>
}

export default SubGoodsTable


